package com.jielin.handling.controller.dzzj;

import java.io.IOException;
import java.util.HashMap;

import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

import com.alibaba.fastjson.JSONObject;

public class HttpClientTest {
    public static void main(String[] args) {
        try {
            String result = getResult("420106195809140812");
            System.out.println(result);
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
    private static String getResult(String gmsfhm) throws IOException {
        CloseableHttpClient client = HttpClients.createDefault();
        HttpPost httpPost = new HttpPost("http://10.72.39.102:6060/gateway/rest/invoke");
        HashMap<String, String> map = new HashMap<>();
        map.put("JYBH","000");
        map.put("WJMC","000");
        map.put("WJLX","000");
        map.put("SJLY","000");
        map.put("WJLX","000");
        map.put("BFDZ","000");
        map.put("DJSJ","000");
        System.out.println(JSONObject.toJSONString(map));
        StringEntity entity = new StringEntity(JSONObject.toJSONString(map), ContentType.APPLICATION_JSON);
        entity.setContentEncoding("UTF-8");
        httpPost.addHeader("IDCardNo","420221197206240417");
        httpPost.addHeader("serviceId","8CA82EEFDABD78E3EF50DE06133BD53F ");
        httpPost.addHeader("instanceId","6A48F8E7C69D1E745F825CDF0C4594A6 ");
        httpPost.addHeader("idUnique","127.0.0.1");//调用人ip
        httpPost.addHeader("orgName","fang");//调用单位名称
        httpPost.addHeader("orgCode","888888888888");//单位代码
        httpPost.addHeader("userName","test");// 使用人
        //httpPost.addHeader("Content-Type","application/json");
        httpPost.setEntity(entity);
        CloseableHttpResponse execute = client.execute(httpPost);
        String s = EntityUtils.toString(execute.getEntity(), "UTF-8");
        return s;
    }
}